package com.vita.testCore.put;

import com.vita.testCore.CvtExecute1;
import com.vita.testCore.CvtStep;
import com.vita.testCore.CvtExecute;
import com.vita.testCore.func.CvtExecuteInOut;
import com.vita.testCore.value.Entry;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Output （累加输出操作符）：
 * 所有的 Output(O o) 内容都会累加到一个list里面
 */
public class Output<I,O> implements CvtStep {
    private List<I> inputs;
    private List<O> outputs;

    public Output(List<I> list,O o) {
        this.inputs = list;
        this.outputs = new ArrayList<>();
        this.outputs.add(o);
    }

    public Output(List<I> inputs,List<O> outputs) {
        this.inputs = inputs;
        this.outputs = outputs;
    }

    public Output<I,O> output(O o){
        this.outputs.add(o);
        return this;
    }

    public Output<I,O> output(List<O> list){
        this.outputs.addAll(list);
        return this;
    }

    public List<O> getOutputs() {
        return outputs;
    }

    public List<I> getInputs() {
        return inputs;
    }

//    @Override
    public void plan(CvtExecute execute) {
        Objects.requireNonNull(execute, "请构建执行器TaskExecute");
        if(!(execute instanceof CvtExecuteInOut)){
            throw new ClassCastException("Output<I> 列表输入必须使用 CvtExecuteFunc2 执行器");
        }

        CvtExecuteInOut ce = (CvtExecuteInOut) execute;

        if (this.inputs.size()>1 || this.outputs.size()>1){
            ce.input(new Entry<>(inputs,outputs));
            ce.run(inputs,outputs);
        }else {
            I input = inputs.get(0);
            O output = outputs.get(0);
            ce.input(new Entry<>(input,output));
            ce.run(input,output);
        }
    }

    @Override
    public void plan(CvtExecute1 execute) {

    }
}
